package com.xiaoming.mall.member.controller;

import com.xiaoming.common.utils.R;
import com.xiaoming.mall.member.entity.MemberEntity;
import com.xiaoming.mall.member.feign.CouponFeignService;
import com.xiaoming.mall.member.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author sangxiaoming
 * 测试远程调用类
 */
@RequestMapping("member/test")
@RestController
public class MemberFeignTestController {

    @Autowired
    private CouponFeignService couponFeignService;

    @Autowired
    private MemberService memberService;


    /**
     * 查询会员信息以及跟会员相关的优惠券信息
     * @return {}
     */
    @RequestMapping("coupons")
    public R test() {
        // 模拟查询会员信息
        MemberEntity memberEntity = new MemberEntity();
        memberEntity.setNickname("会员昵称张三");
        // 远程调用查询优惠券信息
        R memberCoupons = couponFeignService.memberCoupons();
        // 返回
        return Objects.requireNonNull(R.ok().put("member", memberEntity)).put("coupons", memberCoupons.get("coupons"));
    }

}
